<?php

	class TypeController extends CommonController{

		public $model;

		public function __init(){
			//防止覆盖父类的__init();
			parent::__init();

			$this->model=K('Shop_type');

		}

		public function Index(){

			$type_data = $this->model->all();
			//分配数据到html页面
			$this->assign('type_data',$type_data);
			//显示首页
			$this->display();
		}

		//添加类型方法
		public function add(){

			if (IS_POST) {
				if (!$this->model->add_type()) {
					//如果添加不成功就返出模型中的错误
					$this->error($this->model->error);
				}
				$this->success('添加成功');
			}

			//添加类型
			

			$this->display();
		}

		//修改类型
		public function edit(){

			$tid = Q('get.tid',0,'intval');
			$data = $this->model->where("tid={$tid}")->find();
			$this->assign('data',$data);
			if (IS_POST) {
				$tid = Q('get.tid',0,'intval');

				if (!$this->model->edit_type($tid)) {
					$this->error($this->model->error);
				}
				$this->success('类型修改成功');

			}
			//显示编辑模板
			$this->display();
		}

		public function del(){

			$tid = Q('get.tid',0,'intval');

			$this->model->where("tid={$tid}")->del();

			$this->success('删除成功');
		}
	}











?>